package com.zm.boss.service.common.enums;

import java.util.Optional;
import java.util.stream.Stream;

/**
 * 业务异常状态码枚举
 */
public enum ErrorCodeEnum {

    // 公共状态 F10xx
    SYSTEM_SUCCESS("S0001","成功"),
    SYSTEM_EXCEPTION("F9999","系统异常!"),
    SYSTEM_BUSY_EXCEPTION("F8888","系统繁忙，请稍后再试..."),
    SYSTEM_NET_EXCEPTION("F5555", "系统通讯异常"),
    PARAM_FORMAT ("F2222", "参数校验错误: "),
    SIGN_ERROR("F1111", "签值错误"),

    // 商户相关 F11xx
    MERCHANT_NO_NOT_EXIST("F1101", "商户号错误"),
    MERCHANT_NAME_EXIST("F1102", "商户名称已存在"),
    MERCHANT_MOBILE_EXIST("F1103", "商户手机号码已存在"),

    MERCHANT_EMAIL_EXIST("F1104", "商户号邮箱已存在"),
    MERCHANT_LOGIN_NAME_EXIST("F1105", "商户号登录名称已存在"),
    MERCHANT_ACCOUNT_ERROR("F1106","商户账户异常" ),
    MERCHANT_NOTRADE_ERROR("F1107","商户不支持交易" ),
    MERCHANT_ACCOUNT_BALANCE_INSUFFICIENT("F1108", "商户账户余额不足"),
    MERCHANT_PRODUCT_RATE_ERROR("F1109", "商户提现费率未配置"),

    // 订单相关 F12xx
    TRADE_INFO_ERROR("F1003", "订单信息不存在"),
    TRADE_STATUS_ERROR("F1202", "订单状态异常"),
    TRADE_NO_IS_EXITED("F1203", "订单号重复"),
    TRADE_EXPIRED("F1204", "订单已失效,请回到商户页面生成新订单"),
    TRADE_HAD_BEEN_REVIEW("F1205", "该记录已被其他管理员操作。"),
    IS_CHECKING_FLOW("F1206", "其他操作员正在核对流水请稍候再试。"),
    DUPLICATE_CHECK_FLOW("F1207", "核对流水重复。"),

    // 设备相关 F13xx
    NO_AVAILABLE_DEVICE("F1301","找不到可用的设备"),
    DEVICE_CONNECT_ERROR("F1302", "指定设备无响应"),
    PLATFORMISBLANK("F1303", "收款产品为空"),
    MERCHANTISNOTEXITED("F1304", "商户不存在"),
    MERCHANTNOTACCOUNTNO("F1305", "商户未绑定支付宝/微信账号"),
    APPIDISBLANK("F1306", "appId为空"),
    NOTFOUNDPLATFORM("F1307", "未找到相关服务"),
    NOTOPENPLATFORM("F1308", "未开通服务"),
    QRCODE_DELETE_ERROR("F1309", "收款码为删除失败！"),
    DEVICE_IS_USE("F1310","当前设备正在使用!"),
    PAYEE_ACCOUNT_IS_EXITED("F1311","该产品下此账户已存在，请更换后重试"),
    PAYEE_ACCOUNT_NOT_FIND("F1312","收款账户不存在"),
    PAYEE_ACCOUNT_DONOT_BE_DELETED("F1313","账户为可用状态，不可删除"),
    NOTIFY_ERROR("F1314","已发通知，下游返回"),
    ACCOUNT_ALIAS_IS_EXITED("F1315","账户别名重复"),
    CANNOT_DELETE_BF_PHONE_AND_CRAWL("F1316","不可删除！爬虫或设备连接正常"),
    CANNOT_UPDATE_BF_PHONE_AND_CRAWL("F1316","不可编辑！爬虫或设备连接正常"),
    PAYEE_ACCOUNT_DONOT_BE_UPDATE("F1317","账户为可用状态，不可编辑"),
    ROUTER_FAILURE("F1318", "路由失败"),

    // 收款账户相关 F14xx
    ACCOUNT_NOT_EXIST("F1401", "收款账户错误"),

    // api调用出码相关 F15xx
    API_CODE_ERROR("F1501", "出码失败"),
    GET_USER_INFO_ERROR("F1502", "获取用户信息失败"),
    AMOUNT_LIIMT_ERROR("F1503", "付款金额不能小于1元"),

    //WEBSOCKET相关
    WEBSOCKET_TARGE_NOT_FIND("F1901","未找到处理类"),

    //BANK_CARD相关
    BANK_CARD_IS_EXITED("F2000","已存在相同银行卡"),
    BANK_CARD_IS_UNABLE("F2001","该收款账户已停用，请更换后重试"),

    //提现
    ERROR_NOTFOUNDORDERS("F11009","未找到订单"),
    ERROR_CHANNELERROR("F11017","channel连接异常"),
    ERROR_TRADECHONGFU("F11013","订单正在处理中"),
    ERROR_PAYRESULTQUERYFAILED("F11018","交易查询失败"),
    ERROR_TRADESTATUSUPDATEDFAILED("F11011","订单状态修改失败"),
    ERROR_TARDESTATUSNOTNORMAL("F11012","订单状态异常"),
    ERROR_MERCHANTNOT("F11013","暂无可用通道"),
    PROCESSINGACCOUNTERROR("E9999","提现账务异常"),
    ERROR_PROCESSINGACCOUNTFAILED("F11028","账务处理失败"),
    ERROR_SERVICETIMEOUT("F11027","服务器繁忙"),
    ERROR_DELETE_WITHDRAW_CUSTOMER("F11029","删除客户信息失败"),
    ERROR_CHANGE_TRADE_STATUS("F11030","订单号：{0}，交易状态已改为{1}"),
    RIGHT_TO_WITHDRAW_MONEY_FOR_THE_CURRENT_TYPE_OF_BUSINESS("F11031","当前所属的商户类型暂无提现权限"),
    SINGLE_ALLOWANCE_IN_LIEU_OF_A_SINGLE_ALLOWANCE("F11032","单笔代付超过单笔限额"),
    CHANNEL_NAME_EXITS("F11033","通道名称已存在！"),
    //账户相关
    ACCOUNT_BALANCE_IS_SMALL("F9020","账户余额不足!"),

    BANK_NAME_ERROR("-99999", "银行名称填写错误或者该渠道不支持该银行,或者省，市，支行名称为空、该渠道不支持对公"),
    MOBILE_EXIST("F11040", "手机号码已注册"),
    CUSTOMER_INFO_EXIST("F11041","商户信息重复"),
    PLATFORM_LEVEL_EXIST("F11042","该平台下的层级已存在"),
    BANK_TYPE_NONSUPPORT("F11043","当前不支持此类型银行"),
    BANK_CARD_NO("F1045","card_no不能重复"),

    ERROR_ROUTE_MODIFICATION_FAILED("F11051","承兑商路由规则修改失败"),
    ERROR_MINTER_PRODUCT_EXITS("F11052","该产品已开通"),
    ERROR_MINTER_PRODUCT_ACCOUNT_EXITS("F11053","该产品下该账号已存在"),
    ERROR_MINTER_PRODUCT_NOT_EXITS("F11054","产品码不存在"),

    //任务相关
    TASK_CANCELED("F11070","当前任务已取消"),
    SIGN_IN_TASK_MINTER__NOILLEGAL("F11071","每日签到任务 承兑号 不合法"),
    SIGN_IN_TASK_NO_NONENTITY("F11072","每日签到任务 任务号 不存在"),
    SIGN_IN_TASK_NO_CANNOT_NULL("F11073","每日签到任务 任务号不能为空"),
    SIGN_IN_TASK_TYPE_CANNOT_NULL("F11074","每日签到任务 任务类型不能为空"),
    TASK_ADD_FAILED("F11075","任务增加 失败"),
    TASK_UPDATE_FAILED("F11076","任务 修改状态失败"),
    IDCARD_AUTH_FAILED("F11077","身份证认证失败"),
    ERROR_DELETE_NEWS("F11078","删除资讯失败"),
    NO_PLATFORM_NUMBER("F11079","缺少平台号"),

    //app版本升级相关
    LOCK_APP_TYPE("F12001","缺少app类型 参数"),
    LOCK_APP_VER("F12002","缺少app版本格式"),
    LOCK_CONTEBT("F12003","缺少app内容说明参数"),
    LOCK_TITLE("F12004","缺少 app升级标题参数"),
    APP_VER_INCORRCT_FORMAT("F12005","app 版本格式不正确"),
    APP_VER_ALREADY_EXIST("F12006","当前版本号 已存在"),
    LOCK_ID("F12007","缺少id"),
    IRREGULARITIES("F11080","不符合规范的url"),
    IS_DEFAULT_CARD_EXIST("F11081","优先级已存在！"),
    AUTH_ERROR("F11082","认证不通过！"),


    //事件
    CODE_REPETITION("F11092","code不能重复"),
    TEMPLATE_NUll("F11093","猫多多短信模版不存在"),
    MEND_SHARE_PROFIT_TRADE("F11094","补分润失败,当前交易未完成已分润");


    private String errorCode;

    private String errorMsg;

    ErrorCodeEnum(String errorCode, String errorMsg) {
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public static ErrorCodeEnum getErrorCodeEnum(String errorCode){
        Optional<ErrorCodeEnum> op = Stream.of(ErrorCodeEnum.values()).filter(k -> k.getErrorCode().equals(errorCode)).findFirst();
        return op.orElse(SYSTEM_EXCEPTION);
    }
}
